import { BlockEnum, NodeDefault } from '@/components/workflow/types'
import { generateUUIDv4 } from '@/util/utils'
import { ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
import { IfElseNodeType } from './types'

export const getIfElseDefaultParams = (): any => {
  return {
    // 输入
    /* 如果 if  */
    ifList: [
      {
        inputList: [
          {
            variable: undefined,
            value: undefined,
            type: 'cite',
            value_selector: [],
            conditions: undefined,
            id: generateUUIDv4()
          }
        ],
        ifType: 'and',
        case_id: generateUUIDv4()
      }
    ]
    // outputList: [
    //   {
    //     variable: 'output',
    //     value: '大模型输出',
    //     type: 'string',
    //     value_selector: []
    //   }
    // ]
  }
}

const IfElseDefault: NodeDefault<IfElseNodeType> = {
  defaultValue: { ...getIfElseDefaultParams() },
  getAvailablePrevNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS
    return nodes
  },
  checkValid(payload: IfElseNodeType) {
    let isValid = true
    let errorMessages = ''
    if (payload.type) {
      isValid = true
      errorMessages = ''
    }
    return {
      isValid,
      errorMessage: errorMessages
    }
  }
}

export default IfElseDefault
